//
//  NSObject+HBCategory.m
//  HBLibary
//
//  Created by Rambo on 2018/6/8.
//

#import "NSObject+HBCategory.h"
#import <objc/message.h>

@implementation NSObject (HBCategory)

/**
 交换示例方法
 
 @param cls 交换方法的类
 @param originSel 源方法
 @param newSel 交换后的新方法
 */
+ (void)hb_swizzlingInstanceMethodWithClass:(Class)cls originSel:(SEL)originSel newSel:(SEL)newSel{
    
    Method originMethod = class_getInstanceMethod(cls, originSel);
    Method newMethod = class_getInstanceMethod(cls, newSel);
    
    if (class_addMethod(cls, originSel, method_getImplementation(newMethod), method_getTypeEncoding(newMethod))) {
        class_replaceMethod(cls, newSel, method_getImplementation(originMethod), method_getTypeEncoding(originMethod));
    }else{
        method_exchangeImplementations(originMethod, newMethod);
    }
    
}

@end
